#!/usr/bin/env python
# -*- coding: UTF-8 -*-
#
# Copyright [Gtlions Lai].
# Create Date:
# Update Date:
"""summarization ahout this script.

detail ahout this script

   Class(): summarization about Class
   ...
   function(): summarization about function
   ...
"""
__authors__ = '"Gtlions Lai" <gtlions.l@qq.com>'

import sys

from PyQt4 import QtGui, QtSql


class dbmanager(QtGui.QWidget):
    def __init__(self):
        super(dbmanager, self).__init__(parent=None)
        self.db = QtSql.QSqlDatabase.addDatabase("QPSQL")
        self.db.setHostName("gtlions")
        self.db.setDatabaseName("gtlions")
        self.db.setPort(5432)
        self.db.setUserName("gtlions")
        self.db.setPassword("000000")
        if (self.db.open()):
            pass
        else:
            print u"数据库打开失败."
            return
        self.query = QtSql.QSqlQuery()
        self.query.exec_("select id,pid,tips from menuinfo where id=13")
        for i in range(self.query.size()):
            self.query.next()
            record = self.query.record()
            # print self.query.value(0).toInt()[0], self.query.value(1).toInt()[0], self.query.value(2).toString()[0]
            print record.count() # 列数
            for col in range(record.count()):
                print 'vaules:',
                print kex.gtcom.qtcom.qstringtostr(record.value(col).toString())

        sys.exit()
        # self.query.exec_("select id,pid,tips from menuinfo")
        # for i in range(self.query.size()):
        #     self.query.next()
        #     print self.query.value(0).toInt()[0], self.query.value(1).toInt()[0]#, self.query.value(2).toString()[0]

        self.model = QtSql.QSqlTableModel()
        self.model.setQuery(self.query)
        self.layout = QtGui.QGridLayout(self)
        self.view = QtGui.QTableView(self)
        self.view.setModel(self.model)
        # self.view.show()
        self.layout.addWidget(self.view)


if __name__ == "__main__":
    app = QtGui.QApplication(sys.argv)
    db = dbmanager()
    db.show()
    sys.exit(app.exec_())


